package com.iknight.theory.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iknight.theory.api.TeContainerService;
import com.iknight.theory.mapper.TeContainerMapper;
import com.iknight.theory.model.TEContainerModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class TeContainerServiceImpl implements TeContainerService<TEContainerModel, String> {
    @Autowired
    private TeContainerMapper<TEContainerModel, String> teContainerMapper;

    @Override
    public void save(TEContainerModel record) {
        if (null == teContainerMapper.selectOne(record.getContainer_id())) {
            teContainerMapper.insert(record);
        } else {
            teContainerMapper.update(record);
        }
    }

    @Override
    public void delete(String pkey) {
        teContainerMapper.delete(pkey);
    }

    @Override
    public TEContainerModel selectOne(String pkey) {
        return teContainerMapper.selectOne(pkey);
    }

    @Override
    public PageInfo<TEContainerModel> selectPage(Map<String, Object> params, int pageStart, int pageSize) {
//        return null;
        PageHelper.startPage(pageStart, pageSize, true);
        List<TEContainerModel> result = teContainerMapper.selectByCond(params);
        PageInfo<TEContainerModel> page = new PageInfo<>(result);
        return page;
    }

    @Override
    public void batchSave(List<TEContainerModel> entities) {
        for (TEContainerModel model : entities) {
            this.save(model);
        }
    }

    @Override
    public List<Map> getConsPowerByLine(String line_id) {
        return teContainerMapper.getConsPowerByLine(line_id);
    }
}
